#include <iostream>
#include <stack>

using namespace std;

bool judge_reverse(const string& R)
{
        size_t i, j;
        for (i = 0, j = R.size()-1; i < j; i++, j--)
        {
                if (R[i] != R[j])
                        return false;
        }
        return true;
}

int main()
{
        string d2c = "0123456789ABCDEF";
        string R = "";
        stack<char> S;
        int N;
        int b;
        cin >> N >> b;
        if (N < 0)
        {
                R = "-";
                N = -N;
        }
        do {
                S.push(d2c[N%b]);
                N /= b;
        } while (N != 0);
        R.reserve(R.size() + S.size());
        while (!S.empty())
        {
                R.push_back(S.top());
                S.pop();
        }
        // cout << R << endl;
        if (judge_reverse(R))
                cout << "YES" << endl;
        else
                cout << "NO" << endl;
        return 0;
}